package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.pojo.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.DishService;
import com.sky.vo.DishFlavorsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/dish")
public class DishController {
    @Autowired
    private DishService dishService;
    /*
    * 新增菜品
    * */
    @PostMapping
    public Result saveDish(@RequestBody DishDTO dishDTO){
       dishService.saveDish(dishDTO);
        return Result.success();
    }

    /*
    * 修改菜品
    * */
    @PutMapping
    public Result putDish(@RequestBody DishDTO dishDTO){
        dishService.putDish(dishDTO);
        return Result.success();
    }

    /*
    * 根据分类id查询菜品
    * */
    @GetMapping("/list")
    public Result selectCategoryId(Long categoryId){
        Dish dish=dishService.selectCategoryId(categoryId);
        return Result.success(dish);
    }

    /*
    * 删除多个菜品
    * */
    @DeleteMapping
    public Result deleteDishByIds(@RequestParam List<Long> ids){
        dishService.delectDishByIds(ids);
        return Result.success();
    }

    /*
    * 分页条件查询
    * */
    @GetMapping("/page")
    public Result pageDish(DishPageQueryDTO pageQueryDTO){
        PageResult pageResult =dishService.pageDish(pageQueryDTO);

        return Result.success(pageResult);
    }

    /*
    * 查询菜单及口味
    * */
    @GetMapping("/{dishId}")
    public Result selectDishWithFlavor(@PathVariable("id") Long id){
       DishFlavorsVO dishVO= dishService.selectDishWithFlavor(id);
        return Result.success(dishVO);
    }
}
